import machine
import time
import os
from os import *
debugflag=False
class Logs:
    def __init__(self,logname,flag):
        pass
        t = time.localtime()
        self.filename ='{}-{}-{}'.format(t[0], t[1], t[2], t[3], t[4], t[5])
        self.filename =logname+self.filename+'.log'
        self.flag=flag
      
    def append(self,*args):
        if self.flag!=True:
            return        
        info=''
        for arg in args:
            info =info+' '+str(arg)
        t = time.localtime()
        infostr =info+'  {}-{}-{} {}:{}:{}'.format(t[0], t[1], t[2], t[3], t[4], t[5])
        print(infostr)
        path="/"
        with open(path+self.filename, 'a') as file:
            file.write('\n'+infostr)
            file.close()
            
    def appenderror(self,*args):
        info=''
        for arg in args:
            info =info+' '+str(arg)
        t = time.localtime()
        infostr =info+'  {}-{}-{} {}:{}:{}'.format(t[0], t[1], t[2], t[3], t[4], t[5])
        print(infostr)
        path="/"
        with open(path+self.filename, 'a') as file:
            file.write('\n'+infostr)
            file.close()        

    def getsize(self,filename=""):
        os.sync()
        file_stats = os.stat(filename)
        print(file_stats)
        file_size = file_stats[6]
        print("file_size:",file_size)
        return file_size
